package org.phantom.securityframework.local;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.phantom.securityframework.api.PlatformManager;
import org.springframework.stereotype.Service;

import org.phantom.securityframework.api.domain.Platform;

@Service
public class PlatformManagerLocalImpl implements PlatformManager{

	@Resource
	private SqlSession sqlsession = null;

	@Override
	public Platform get(String platformId) {
		return (Platform) sqlsession.selectOne("org.phantom.securityframework.PlatformMapper.get",platformId);
	}

	@Override
	public Platform save(Platform platform) {
		if(platform.getPlatformId()==null || "".equals(platform.getPlatformId())){
			throw new RuntimeException("platformName can not be null");
		}
		if(this.get(platform.getPlatformId())!=null){
			throw new RuntimeException("platformName must be unique!");
		}
		sqlsession.insert("org.phantom.securityframework.PlatformMapper.save",platform);
		return platform;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Platform> list() {
		return sqlsession.selectList("org.phantom.securityframework.PlatformMapper.list");
	}


	
}
